/**
 *  example.c
 *
 *  Copyright (c) 2007 INdT (Instituto Nokia de Technologia)
 *                2007 Marcelo Lira dos Santos <setanta@gmail.com>
 *
 *  Author: Marcelo Lira dos Santos <setanta@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA
 */

#include <hildon/hildon.h>
#include <gtk/gtk.h>
#include <glib.h>

HildonProgram *program;
HildonWindow *window;

GtkVBox* vbox1;
GtkHBox* hbox1;
GtkLabel* label1;
GtkLabel* label2;
GtkEntry* entry1;
GtkButton* button1;
GtkHSeparator* separator;

static void construct();
static void do_write_message();
static void on_entry1_activated (GtkEntry* entry);
static void on_button1_clicked (GtkButton* button);

int main (int argc, char ** argv)
{
    gtk_init(&argc, &argv);

    program = HILDON_PROGRAM(hildon_program_get_instance());
    g_set_application_name("Sample");

    window = HILDON_WINDOW(hildon_window_new());
    hildon_program_add_window(program, window);

    construct();

    g_signal_connect(G_OBJECT(window), "delete_event",
                     G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(GTK_WIDGET(window));
    gtk_main();

    return 0;
}

static void construct()
{
    vbox1 = GTK_VBOX(gtk_vbox_new (FALSE, 4));
    gtk_container_set_border_width (GTK_CONTAINER (vbox1), 4);

    hbox1 = GTK_HBOX(gtk_hbox_new (FALSE, 4));
    label1 = GTK_LABEL(gtk_label_new ("Write something:"));
    gtk_box_pack_start (GTK_BOX (hbox1), GTK_WIDGET (label1), FALSE, FALSE, 0);

    entry1 = GTK_ENTRY(gtk_entry_new ());
    g_signal_connect(G_OBJECT(entry1), "activate",
                     G_CALLBACK(on_entry1_activated), NULL);
    gtk_box_pack_start (GTK_BOX (hbox1), GTK_WIDGET (entry1), TRUE, TRUE, 0);

    button1 = GTK_BUTTON(gtk_button_new_from_stock ("gtk-apply"));
    g_signal_connect(button1, "clicked",
                     G_CALLBACK(on_button1_clicked), NULL);
    gtk_box_pack_start (GTK_BOX (hbox1), GTK_WIDGET (button1), FALSE, FALSE, 0);

    gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET (hbox1), FALSE, TRUE, 0);

    separator = GTK_HSEPARATOR(gtk_hseparator_new ());
    gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET (separator), FALSE, TRUE, 2);

    label2 = GTK_LABEL(gtk_label_new (""));
    g_object_set (GTK_MISC (label2), "xalign", 0.0, NULL);
    gtk_label_set_line_wrap (label2, TRUE);
    gtk_box_pack_start_defaults (GTK_BOX (vbox1), GTK_WIDGET (label2));

    gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox1));
}

static void on_entry1_activated (GtkEntry* entry)
{
    do_write_message();
}

static void on_button1_clicked (GtkButton* button)
{
    do_write_message();
}

static void do_write_message()
{
	char* msg;
	msg = NULL;
    msg = g_strconcat ("<b>You've written:</b> ",
                       gtk_entry_get_text(entry1),
                       NULL);

    gtk_label_set_markup (label2, msg);

	g_free (msg);
}

